<template>
  <el-menu default-active="2" :router="true" class="el-menu-vertical-demo" background-color="#545c64" text-color="#fff"
           active-text-color="#70A8E1FF" @open="handleOpen" @close="handleClose" :collapse="isCollapse">
    <div>
      <img src="../assets/images/logo.png" alt="软件协会" style="width: 60px;">
      <h3 style="margin-left: 10px;">考试系统</h3>
    </div>
    <el-menu-item :index="item.path" @click="clickMenu(item)" v-for="item in noChildren" :key="item.path">
      <i :class="'el-icon'+item.icon"></i>
      <span slot="title">{{ item.label }}</span>
    </el-menu-item>
    <el-submenu @click="clickMenu(item)" v-for="item in hasChildren" :index="item.path" :key="item.path">
      <template slot="title">
        <i :class=" 'el-icon'+item.icon"></i>
        <span slot="title">{{ item.label }}</span>
      </template>
      <el-menu-item-group v-for="subItem in item.children" :key="subItem.path">
        <el-menu-item :index="subItem.path">{{ subItem.label }}</el-menu-item>
      </el-menu-item-group>
    </el-submenu>
  </el-menu>
</template>
<script>

export default {
  name: "CommonAside",
  data() {
    return {
      isCollapse: false,
      menu: [
        {
          path: '/',
          name: 'home',
          label: '首页',
          icon: '-s-home'
        },
        {
          path: 'classManage',
          name: 'classManage',
          label: '课程管理',
          icon: '-s-claim',
          children: [
            {
              path: '/teacherClass',
              name: 'teacherClass',
              label: '班级管理'
            },
            {
              path: '/studentMessage',
              name: 'studentMessage',
              label: '学生管理'
            },
            {
              path: '/addClass',
              name: 'addClass',
              label: '学科管理'
            }
          ]
        },
        {
          path: 'question',
          name: 'question',
          label: '题库管理',
          icon: '-circle-plus',
          children: [
            {
              path: '/add-question',
              name: 'add-question',
              label: '添加题目'
            },
            {
              path: '/add-knowledge',
              name: 'add-knowledge',
              label: '添加知识点'
            },
            {
              path:'/shareQuestions/shareQues',
              name:'shareQues',
              label:'共享题库',
            }
          ]
        },
        {
          path: 'testPaper',
          name: 'testPaper',
          label: '组卷管理',
          icon: '-s-platform',
          children: [
            {
              path: '/aiTestPaper',
              name: 'aiTestPaper',
              label: '智能组卷'
            },
            {
              path: '/peopleTestPaper',
              name: 'peopleTestPaper',
              label: '人工组卷'
            }
          ]
        },
        {
          path: 'examination',
          name: 'examination',
          label: '考试管理',
          icon: '-s-management',
          children: [
            {
              path: '/examMessage',
              name: 'examMessage',
              label: '考试列表'
            },
            {
              path: '/historyPaper',
              name: 'historyPaper',
              label: '历史试卷'
            },
            {
              path: '/paperMessage',
              name: 'paperMessage',
              label: '试卷库'
            },
          ]
        },
        {
          path: 'paperManage',
          name: 'paperManage',
          label: '答卷管理',
          icon: '-s-opportunity',
          children: [
            {
              path: '/correctPaper',
              name: 'correctPaper',
              label: '批改试卷'
            }
          ]
        },
        {
          path: 'achievementAnalysis',
          name: 'achievementAnalysis',
          label: '考后管理',
          icon: '-s-data',
          children: [
            {
              path: '/achievementStatistic',
              name: 'achievementStatistic',
              label: '统计分析'
            }
          ]
        },
        // 公共平台已被移植到学生端
        // {
        //   path: '/publicPlatform/questionGroup',
        //   name: 'questionGroup',
        //   label: '公共平台',
        //   icon: '-postcard'
        // }
        // 公共平台已被移植到学生端
        // {
        //   path: '/teachpublicPlatform/questionGroup',
        //   name: 'questionGroup',
        //   label: '公共平台',
        //   icon: '-postcard'
        // }
      ]
    };
  },
  methods: {
    handleOpen(key, keyPath) {
      // console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      // console.log(key, keyPath);
    },
    clickMenu(item) {
      this.$router.push({
        name: item.name
      });
    }
  },
  computed: {
    noChildren() {
      return this.menu.filter(item => !item.children)
    },
    hasChildren() {
      return this.menu.filter(item => item.children)
    }
  }
}
</script>


<style lang="less" scoped>
div {
  display: flex;

  img {
    width: 40px;
    height: 60px;
    padding-top: 12px;
  }
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}

.el-menu {
  height: 100%;
  padding-left: 20px;
  border: none;

  h3 {
    display: inline-block;
    color: #fff;
    text-align: center;
    line-height: 48px;
  }

  span {
    padding-left: 10px;
  }
}
</style>
